<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./JavaScript/jquery-3.7.1.js"></script>
    <style>
      .box1 {
        float: left;
        width: 100px;
        height: 100px;
        border: 1px red solid;
        margin: 10px;
      }

      .box2 {
        float: left;
        width: 200px;
        height: 200px;
        border: 1px orange solid;
      }
    </style>

    <script>
      $(function () {
        $('#btn01').click(function () {
          // end() 将jQuery对象恢复到筛选前的状态
          // add() 向jQuery对象中添加元素
          // contents() 获取当前jQuery对象中所有元素的内容

          // $(".box1")
          //     .filter(".a")
          //     .css("background-color", "#bfa")
          //     .end()
          //     .css("border-color", "blue")
          // $(".box1")
          //     .css("border-color", "blue")
          //     .filter(".a")
          //     .css("background-color", "#bfa")

          // $(".box1").add(".box2").css("background-color", "#bfa")

          $('.box1').contents().addBack().css('background-color', '#bfa');
        });
      });
    </script>
  </head>
  <body>
    <button id="btn01">点我</button>

    <hr />

    <div class="box1"><span>我是span</span></div>
    <div class="box1"><span>我是span</span></div>
    <div class="box1"><span>我是span</span></div>
    <div class="box1 a"><span>我是span</span></div>
    <div class="box1 a"><span>我是span</span></div>
    <div class="box1 a"></div>
    <div class="box1"></div>
    <div class="box1 a"></div>
    <div class="box1"></div>
    <div class="box1"></div>

    <div class="box2"></div>
  </body>
</html>
